//
//  SRFindPwdView.m
//  SportRing
//
//  Created by Apple on 14/10/23.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRFindPwdView.h"

@interface SRFindPwdView ()

@property (nonatomic, weak) IBOutlet UITextField * mobileTF;
@property (nonatomic, weak) IBOutlet UITextField * authCodeTF;
@property (nonatomic, weak) IBOutlet UITextField * passwordTF;

@property (nonatomic, weak) IBOutlet LGButton * okBtn;

@end

@implementation SRFindPwdView

-(void)awakeFromNib
{
    [super awakeFromNib];
    
//    [self setupButtons];
    if (!([UIScreen mainScreen].bounds.size.height > 480)) {
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"loginBg480"]];
    }else
    {
      self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"loginBg"]];  
    }
    
    _mobileTF.layer.borderWidth = 0;
    RAC(self.sendAuthBtn, enabled) = [RACSignal combineLatest:@[self.mobileTF.rac_textSignal]
                                                       reduce:^(NSString * mobile) {
                                                           return @(mobile.length > 0);
                                                       }];
    
    RAC(self.okBtn, enabled) = [RACSignal combineLatest:@[self.authCodeTF.rac_textSignal,
                                                          self.passwordTF.rac_textSignal]
                                                 reduce:^(NSString * authCode, NSString * password) {
                                                     return @(authCode.length > 0 && password.length > 0);
                                                 }];
    
    @weakify(self);
    
    [[self.sendAuthBtn rac_signalForControlEvents:UIControlEventTouchUpInside]
     subscribeNext:^(id x) {
         
         [SVProgressHUD showSuccessWithStatus:@"发送验证码"];
         [self_weak_.delegate doSendAuthCodeAction:self_weak_.mobileTF.text];
    }];
    
    [[self.okBtn rac_signalForControlEvents:UIControlEventTouchUpInside]
     subscribeNext:^(id x) {
         [SVProgressHUD showSuccessWithStatus:@""];
         [self_weak_.delegate doModifyNewPasswordAction:self_weak_.passwordTF.text
                                               authCode:self_weak_.authCodeTF.text phoneNumber:self_weak_.mobileTF.text];
    }];
}



- (void)setupButtons
{
    LGButtonColorPair * normalColor1 = [LGButtonColorPair colorPairWithTitleColor:[UIColor whiteColor]
                                                                  backgroundColor:[UIColor colorWithRed:113.0/255.0
                                                                                                  green:183.0/255.0
                                                                                                   blue:20.0/255.0
                                                                                                  alpha:1.0f]];
    [self.sendAuthBtn setColorPairs:@{@(LG_BUTTON_STATE_TYPE_NORMAL):normalColor1}];
    
    [self.okBtn setColorPairs:@{@(LG_BUTTON_STATE_TYPE_NORMAL):normalColor1}];
}

@end
